package com.example.vm.controller.user;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.common.domain.BasePage;
import com.common.domain.R;
import com.example.vm.domain.entity.Video;
import com.example.vm.service.VideoService;
import lombok.RequiredArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

@RestController("user-video")
@RequestMapping("/video/user")
@RequiredArgsConstructor
public class VideoController {
    @Autowired
    private VideoService videoService;

    /**
     * 用户查看自己的视频
     * @param basePage
     * @return
     */
    @GetMapping("/list")
    public R listVideo(BasePage basePage){
        return R.ok().data(videoService.listVideo(basePage));
    }
    /**
     * 获取热度排行榜
     */
    @GetMapping("/hotrank")
    public R getHotRank(){
        return R.ok().data(videoService.getHotRank());
    }
    /**
     * 获取热门视频
     */
    @GetMapping("/hotvideo")
    public R getHotVideo(){
        return R.ok().data(videoService.getHotVideo());
    }

    /**
     * 根据分类推荐视频
     * @param typeId
     * @return
     */
    @GetMapping("/typevideo/{id}")
    public R getTypeVideo(@PathVariable("id") Long typeId){
        return R.ok().data(videoService.getTypeVideo(typeId));
    }
    /**
     * 上传视频
     */
    @PostMapping
    public R publishVideo(@RequestBody @Validated Video video){
        videoService.publishVideo(video);
        return R.ok().msg("发布成功，等待审核");
    }
    /**
     * 根据兴趣推荐视频
     */
    @GetMapping("/interest")
    public R getInterestVideo(){
        List<Video> byInterest = videoService.getByInterest();
        return R.ok().data(byInterest);
    }

    /**
     * 获取用户
     * @param id
     * @return
     */
    @GetMapping("/likeNum")
    public R getlikeNum(@RequestParam("id") Long id){
       Long subscribeNum =  videoService.getlikeNum(id);
        return R.ok().data(subscribeNum);
    }

    /**
     * 根据关注推荐视频
     * @return
     */
    @GetMapping("/attention")
    public R getAttentionVideo(){
        return R.ok().data(videoService.getAttentionVideo());
    }

    /**
     * 推荐相似视频
     */
    @GetMapping("/similar")
    public R getSimilarVideo(@RequestParam Long id){
        
        return R.ok().data(videoService.getSimilarVideo(id));
    }
    /**
     * 查看一个用户发布的所有视频
     */
    @GetMapping("/listUserVideo/{id}")
    public R getUserVideo(@PathVariable Long id){
       List<Video> videos= videoService.getUserVideo(id);
        return R.ok().data(videos);
    }
}
